package cn.sunchis.demo.ctrl;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * JSON 表单解析测试
 * @Author 许亮
 * @Create 2018-7-20 16:26:53
 */
@Controller
@RequestMapping("/json")
public class JsonPaserController {
	@RequestMapping(value="/form", method=RequestMethod.GET)
	public String form(Model model) {
		model.addAttribute("pageTitle", "JSON表单解析测试");
		
		LogStash logStash = new LogStash();
		logStash.setVersion("1");
		logStash.setTimestamp("2018-07-20T08:20:21.185Z");
		logStash.setHost("einwin3-bdb07");
		logStash.setMessage("test message");
		model.addAttribute("form", logStash);
		
		return "/pages/home.jsp";
	}
	
	@ResponseBody
	@RequestMapping(value="/formRecieve", method=RequestMethod.POST)
	public LogStash formRecieve(@ModelAttribute LogStash logStash) {
		return logStash;
	}
}
